2020-2021 Sunseeker Telemetry and Lighting System
sd24_b_ex3_contConvSingleChannel.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //*****************************************************************************
33 // MSP430F673x Demo - SD24_B, Continuous Conversion on a Single Channel
34 //
35 // Description: This program uses the SD24_B module to perform continuous
36 // conversions on a single channel. An SD24_B interrupt occurs when a
37 // conversion has completed. Test by applying a voltage to channel 2
38 // (SD2P0, SD2N0) and setting a breakpoint at the line indicated below.
39 // Run program until it reaches the breakpoint, then use the debugger's
40 // watch window to view the conversion results. Results (upper 16 bits only)
41 // for channel 2 are stored in the array "results".
42 // ACLK = n/a, MCLK = SMCLK = DCO = ~ 1.1MHz
43 // //* For Minimum Vcc required for SD24_B module - see datasheet *//
44 // //* 100nF cap between Vref and AVss is recommended when using 1.5V REF *//
45 //
46 // MSP430F673x
47 // -----------------
48 // /|\| XIN|-
49 // | | |
50 // --|RST XOUT|-
51 // | |
52 // Vin+ -->|SD2P0 |
53 // Vin- -->|SD2N0 |
54 // | |
55 // | VREF |---+
56 // | | |
57 // | | -+- 100nF
58 // | | -+-
59 // | | |
60 // | AVss |---+
61 // | |
62 //
63 // M. Swanson
64 // Texas Instruments, Inc
65 // December 2011
66 // Built with CCS Version: 5.1.0 and IAR Embedded Workbench Version: 5.40.1
67 //*****************************************************************************
68 
69 #include "driverlib.h"
70 
71 #define Num_of_Results 8
72 
73 /* Array to store SD24_B conversion results */
75 
76 void main(void)
77 {
78  WDT_A_hold(WDT_A_BASE); // Stop WDT
79 
80  // Select internal REF
81  // Select SMCLK as SD24_B clock source
82  SD24_B_initParam initParam = {0};
83  initParam.clockSourceSelect = SD24_B_CLOCKSOURCE_SMCLK;
84  initParam.clockPreDivider = SD24_B_PRECLOCKDIVIDER_1;
85  initParam.clockDivider = SD24_B_CLOCKDIVIDER_1;
86  initParam.referenceSelect = SD24_B_REF_INTERNAL;
87  SD24_B_init(SD24_BASE, &initParam);
88 
89  SD24_B_setInterruptDelay(SD24_BASE,
90  SD24_B_CONVERTER_2,
91  SD24_B_THIRD_SAMPLE_INTERRUPT);
92 
93 
94  // Enable channel 2 interrupt
95  SD24_B_clearInterrupt(SD24_BASE,
96  SD24_B_CONVERTER_2,
97  SD24_B_CONVERTER_INTERRUPT );
98  SD24_B_enableInterrupt(SD24_BASE,
99  SD24_B_CONVERTER_2,
100  SD24_B_CONVERTER_INTERRUPT );
101 
102  __delay_cycles(0x3600); // Delay for 1.5V REF startup
103 
104  SD24_B_startConverterConversion(SD24_BASE,
105  2); // Set bit to start conversion
106 
107  __bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupts
108 }
109 
110 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
111 #pragma vector=SD24B_VECTOR
112 __interrupt
113 #elif defined(__GNUC__)
114 __attribute__((interrupt(SD24B_VECTOR)))
115 #endif
116 void SD24BISR(void)
117 {
118  static uint16_t index = 0;
119 
120  switch (SD24BIV)
121  {
122  case SD24BIV_SD24OVIFG: // SD24MEM Overflow
123  break;
124  case SD24BIV_SD24TRGIFG: // SD24 Trigger IFG
125  break;
126  case SD24BIV_SD24IFG0: // SD24MEM0 IFG
127  break;
128  case SD24BIV_SD24IFG1: // SD24MEM1 IFG
129  break;
130  case SD24BIV_SD24IFG2: // SD24MEM2 IFG
131  results[index] = SD24_B_getResults(SD24_BASE,
132  SD24_B_CONVERTER_2); // Save CH2 results (clears IFG)
133  if (++index == Num_of_Results)
134  {
135  index = 0; // SET BREAKPOINT HERE
136  }
137  break;
138  }
139 }
140 
__delay_cycles(500000)
#define Num_of_Results
uint32_t results[Num_of_Results]
void SD24BISR(void)